package com.beijiteshop.shop.utils

import android.content.Context
import com.beijiteshop.shop.R
import com.lljjcoder.Interface.OnCityItemClickListener
import com.lljjcoder.bean.CityBean
import com.lljjcoder.bean.DistrictBean
import com.lljjcoder.bean.ProvinceBean
import com.lljjcoder.citywheel.CityConfig
import com.lljjcoder.style.citypickerview.CityPickerView

/**
 * @Author LiaoZhongKai
 * @Date 2021/3/9 11:39
 * @Description 省市区选择
 */
class CityPickUtil private constructor(){

    companion object{
        val instance: CityPickUtil by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED){
            CityPickUtil()
        }
    }

    fun show(context: Context,result: (province: String,city: String,district: String) -> Unit){
        val mCityPickerView = CityPickerView()
        mCityPickerView.init(context)
        val cityConfig = CityConfig.Builder()
            .title(context.resources.getString(R.string.please_select))
            .visibleItemsCount(5)
            .provinceCyclic(false)
            .cityCyclic(false)
            .districtCyclic(false)
            .setCityWheelType(CityConfig.WheelType.PRO_CITY_DIS)
            .setShowGAT(true)
            .setCustomItemLayout(R.layout.item_city)
            .setCustomItemTextViewId(R.id.item_city_name_tv)
            .build()
        mCityPickerView.setConfig(cityConfig)
        mCityPickerView.setOnCityItemClickListener(object : OnCityItemClickListener(){
            override fun onSelected(
                province: ProvinceBean,
                city: CityBean,
                district: DistrictBean
            ) {
                result.invoke(province.name,city.name,district.name)
            }
        })
        mCityPickerView.showCityPicker()
    }
}